package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.LoginDto;
import com.itheima.reggie.domain.User;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author fanYuLe
 * @Date 2023/3/8 11:33
 * @Blog blog.fanYuLe.net/996.mba
 * @Description:
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    //发送短信
    @PostMapping("/user/sendMsg")
    public ResultInfo sendMsg(@RequestBody User user){
        //2.调用service发送短信
        userService.sendMsg(user.getPhone());
        //3.发送成功
        return ResultInfo.success();
    }
    //登录注册
    @PostMapping("/user/login")
    public ResultInfo login(@RequestBody LoginDto loginDto){
        //调用service登录
        String token=userService.login(loginDto.getPhone(),loginDto.getCode());
        //3.返回结果
        return ResultInfo.success(token);
    }
    //推出
    @PostMapping("/user/logout")
    public ResultInfo logout(){
        return ResultInfo.success();
    }
}

